﻿using System;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace ZhukBlogLinqExamples.WebParts.Clock
{
    [ToolboxItemAttribute(false)]
    public class Clock : WebPart
    {
        protected override void CreateChildControls()
        {
SPStatefulLongOperation.Begin(
    "CLOCK",
    "<span id='currentTime'></span>",
    op =>
    {
        op.Run(opState =>
        {
            var currentDate = DateTime.Now;
            var endDate = currentDate.AddMinutes(20);
            while (endDate > DateTime.Now)
            {
                opState.Status = string.Format(
                    //"<script type='text/javascript'>" +
                    //"document.all.item('currentTime').innerText = '{0}';" +
                    //"</script>",
                    "{0}",
                    DateTime.Now.ToString("HH:mm:ss"));
            }
        });
        op.End("http://blog.vitalyzhukov.ru");
    });
        }
    }
}
